home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / rss / icrss.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  15.8 KB  |  463 lines

  1. /*
  2.                               I C R S S . H
  3.  
  4.     header file for icmake run time support system.. generic functions
  5.     are declared here
  6.  
  7.     structure of the binary file:
  8.  
  9.         version                             e.g., "1.00", without ascii-z
  10.         offset of the string constant-area  (long)
  11.         offset of the variable area         (long)
  12.         offset of the filenames area        (long) (end of BIN_HEADER_)
  13.         offset of first instr. to execute   (long)
  14.  
  15.         code                                (first byte is first instruction)
  16.         ascii-z string constant area
  17.         variables
  18.         filenames                           '\n' terminated strings
  19.  
  20.  
  21.     If a logical expression is compiled, it is evaluated using true- and
  22.     false-lists to determine its result as quickly as possible. Then, if the
  23.     expression is not returned to an if- or while- condition, the true-list
  24.     backpatches to the current code position, where a push_1_jmp_end
  25.     instruction is written. Then the falselist is backpatched to the current
  26.     code position and a push_0 opcode is written.
  27.  
  28.     If a logical is expresion is returned to an if- or while-condition, the
  29.     code of the if/while statement is placed beyond the truelist (possibly
  30.     followed by the code of the 'else' part of an if-stmnt).
  31.  
  32.     The runtime stack contains elements of type VAR_. When a element is popped,
  33.     the type of the value and its descriptor are therefor available. push
  34.     instructions must make sure that type and descriptors are pushed
  35.  
  36.     Opcodes:
  37.  
  38.     op_jmp              int-displacement
  39.     op_jmp_false        int-displacement    (implicit pop)
  40.     op_jmp_true         int-displacement    (implicit pop)
  41.  
  42.     op_push_1_jmp_end   jumps 1 byte (beyond push_0)
  43.     op_push_0
  44.     op_push_imm         imm-value
  45.     op_push_strconst    string-index
  46.     op_push_var         var # (var is an int or a list, info in var[#].type)
  47.     op_push_reg         push return register (set by function)
  48.  
  49.     op_pop_var          var # (var is an int or a list, info in var[#].type)
  50.  
  51.     op_umin             unary opcode, negating the stack[sp] value
  52.     op_atoi             string -> int               (type casting)
  53.     op_itoa             int -> string
  54.     op_atol             string -> 1-element list
  55.  
  56.                         binary opcodes pop two operands from the stack,
  57.                         perform operation and push result:
  58.  
  59.                         arithmetic opcodes:
  60.     op_mul
  61.     op_div
  62.     op_mod
  63.     op_add
  64.     op_sub
  65.                         bitwise:
  66.     op_band
  67.     op_bor
  68.     op_bnot
  69.     op_xor
  70.     op_shl
  71.     op_shr
  72.                         logical opcodes, resulting value is always
  73.                                          immediate 1 or 0
  74.     op_eq               ==
  75.     op_neq              !=
  76.     op_sm               <
  77.     op_gr               >
  78.     op_smeq             <=
  79.     op_greq             >=
  80.     op_younger          younger
  81.     op_older            older
  82.  
  83.     op_call funnr       funnr is a byte (see enum FUNNR_)
  84.     op_asp  #args       #args is a byte (asp: add stack pointer, clean stack)
  85.                         ( NOTE on function execute: see below )
  86.     op_exit             terminate command list processing, return
  87.                         stack[sp].intval to operating system
  88.                         (auto generated as the last instruction)
  89.     op_copy_var varnr   stackinfo of formerly popped stackelement to var varnr
  90.     op_inc              increment int variable, varnr is INT16 argument
  91.     op_dec              decrement int variable, varnr is INT16 argument
  92.     op_call INT16       call function at offset
  93.     op_frame INT8 ...   make function frame, for INT8 variables
  94.                         For each variable a byte follows, denoting the type
  95.                         of the local variable. The first byte refers to the
  96.                         first local variable following the position to where
  97.                         BP points (see the info about stackframes).
  98.     op_ret              break frame and return
  99.     op_pop_reg          pop into return register
  100.     op_hlt              not generated instruction, used for internal testing.
  101.  
  102.     Type casts
  103.     ----------
  104.     --------------|----------------------------------
  105.                   |          cast result
  106.                   |----------------------------------
  107.                   |    (int)   (string)    (list)
  108.     --------------|----------------------------------
  109.     cast operand: |
  110.     --------------|
  111.             int   |     ok      itoa        error
  112.                   |
  113.             string|     atoi    ok          atol
  114.                   |
  115.     --------------|----------------------------------
  116.  
  117.  
  118.  
  119.     Operand matrix:
  120.     ---------------
  121.  
  122.             ------|----------------------------------
  123.                   |     int     string      list
  124.             ------|----------------------------------
  125.                   |
  126.             int   |     all
  127.                   |
  128.                   |
  129.             string|             == != >
  130.                   |             < <= >=
  131.                   |             + += =
  132.                   |             older
  133.                   |             younger
  134.             list  |                         == !=
  135.                   |                         + -
  136.                   |                         += -= =
  137.             ------|----------------------------------
  138.  
  139.  
  140.     Stackframes
  141.     -----------
  142.  
  143.     Variable numbers less than 0x8000 refer to global variables.
  144.     Local variables are numbered relative to the value 0xc000,
  145.     indicating [BP]. Thus, the following addressing scheme is followed:
  146.  
  147.         --------------------------------------------------------------
  148.                 Frame:                  Variable numbers:
  149.         --------------------------------------------------------------
  150.                 arg2                    0xc003
  151.                 arg1                    0xc002
  152.                 ra                              (0xc001, not used)
  153.                 old bp  <-bp                    (0xc000, not used)
  154.                 loc1                    0xbfff
  155.                 loc2                    0xbffe
  156.         --------------------------------------------------------------
  157.  
  158.     The op_frame instruction needed for the previous example, assuming
  159.     loc1 of type int, and loc2 of type string, is:
  160.  
  161.                 op_frame    2, e_int, e_str     (opcode and three INT8's)
  162.  
  163.     Functions printf, fprintf
  164.     -------------------------
  165.     The variable number of arguments which are allowed for these functions
  166.     are passed to the executor of icmake in the following manner:
  167.  
  168.     Starting with ICMAKE version 4.00 the mode flag is no longer interpreted.
  169.  
  170.     The modeflag is therefore ignored. A hidden argument, specifying the number
  171.     of arguments, is pushed as a hidden parameter. So, the following statement
  172.     results in the following code:
  173.  
  174.              printf("hello world\n")
  175.  
  176.         push string constant "hello world\n"    // the string itself
  177.         push 1                                  // the number of arguments
  178.         call funnr #x                           // call printf
  179.         add sp, 2                               // clear two arguments
  180.  
  181.     Functions chdir, system, putenv
  182.     -------------------------------
  183.  
  184.     Starting with version 4.00, the mode flag is no longer needed. The
  185.     functions now expect only one string argument. For reasons of compatibility
  186.     with previous versions, a first integer argument is ignored if present.
  187.  
  188.     Functions exec, execute
  189.     -----------------------
  190.  
  191.     Starting with version 4.00, the mode flag no longer specifies delayed or
  192.     immediate processing. The mode flag however still defines whether error
  193.     checking should or should not occur.
  194.  
  195.     The argument handling is, apart from the required first mode flag, similar
  196.     to that of the functions printf and fprintf.
  197.  
  198. */
  199.  
  200. #include "../icm.h"
  201. #include <stdio.h>
  202.  
  203. /*
  204.                     The compiler uses E_TYPE 0 to indicate
  205.                     the void type.
  206. */
  207. typedef enum
  208. {
  209.     /* rss + compiler: */
  210.     e_int           = (1 << 0),             /* int-type    expression */
  211.     e_str           = (1 << 1),             /* string-type expression */
  212.     e_list          = (1 << 2),             /* list-type   expression */
  213.  
  214.     /* compiler only: */
  215.     e_bool          = (1 << 3),             /* bool-type   expression */
  216.  
  217.     e_const         = (1 << 4),             /* immediate value */
  218.     e_var           = (1 << 5),             /* variable */
  219.     e_reg           = (1 << 6),             /* register */
  220.     e_code          = (1 << 7),             /* code */
  221.  
  222.     e_pre_inc_dec   = (1 << 8),             /* pre-inc or pre-dec        */
  223.     e_post_inc_dec  = (1 << 9),             /* post-inc or post-dec      */
  224. } E_TYPE_;
  225.  
  226. typedef enum                                /* names of rss-functions */
  227. {
  228.     f_arg_head,
  229.     f_arg_tail,
  230.     f_ascii_int,                            /* return int */
  231.     f_ascii_str,                            /* return str */
  232.  
  233.     f_c_base,
  234.     f_chdir,
  235.     f_c_ext,
  236.     f_cmd_head,
  237.     f_cmd_tail,
  238.     f_c_path,
  239.  
  240.     f_echo,
  241.     f_element,
  242.     f_exec,
  243.     f_execute,                              /* only used by the compiler */
  244.     f_exists,
  245.  
  246.     f_fields,
  247.     f_fgets,
  248.     f_fprintf,
  249.  
  250.     f_g_base,
  251.     f_getch,
  252.     f_gets,
  253.     f_g_ext,
  254.     f_g_path,
  255.  
  256.     f_makelist,
  257.  
  258.     f_printf,
  259.     f_putenv,
  260.  
  261.     f_sizeoflist,
  262.     f_stat,
  263.     f_str_el,
  264.     f_strlwr,                               /* only used by the compiler */
  265.     f_strupr,                               /* only used by the compiler */
  266.     f_system,
  267.  
  268.                       /* reserved rss function opcodes for subreleases */
  269.     f_strlen,                               /* NEW: only for the compiler */
  270.     f_substr,                               /* IDEM */
  271.     f_getpid,                               /* used by several programs  */
  272.  
  273.     f_hlt = f_system + 10,                  /* dummy marker for non-existing */
  274. } FUNNR_;
  275.  
  276. typedef enum
  277. {                       /* hexnr:     */
  278.     op_jmp,             /*     00     */
  279.     op_jmp_false,       /*     01     */
  280.     op_jmp_true,        /*     02     */
  281.     op_push_1_jmp_end,  /*     03     */
  282.     op_push_0,          /*     04     */
  283.     op_push_imm,        /*     05     */
  284.     op_push_strconst,   /*     06     */
  285.     op_push_var,        /*     07     */
  286.     op_push_reg,        /*     08     */
  287.     op_pop_var,         /*     09     */
  288.     op_umin,            /*     0a     */
  289.     op_atoi,            /*     0b     */
  290.     op_itoa,            /*     0c     */
  291.     op_atol,            /*     0d     */
  292.     op_mul,             /*     0e     */
  293.     op_div,             /*     0f     */
  294.     op_mod,             /*     10     */
  295.     op_add,             /*     11     */
  296.     op_sub,             /*     12     */
  297.     op_eq,              /*     13     */
  298.     op_neq,             /*     14     */
  299.     op_sm,              /*     15     */
  300.     op_gr,              /*     16     */
  301.     op_younger,         /*     17     */
  302.     op_older,           /*     18     */
  303.     op_smeq,            /*     19     */
  304.     op_greq,            /*     1a     */
  305.     op_call_rss,        /*     1b     */
  306.     op_asp,             /*     1c     */
  307.     op_exit,            /*     1d     */
  308.     op_copy_var,        /*     1e     */
  309.     op_inc,             /*     1f     */
  310.     op_dec,             /*     20     */
  311.     op_call,            /*     21     */
  312.     op_frame,           /*     22     */
  313.     op_ret,             /*     23     */
  314.     op_pop_reg,         /*     24     */
  315.     op_band,            /*     25     */
  316.     op_bor,             /*     26     */
  317.     op_bnot,            /*     27     */
  318.     op_xor,             /*     28     */
  319.     op_shl,             /*     29     */
  320.     op_shr,             /*     2a     */
  321.     op_hlt = op_shr + 10/*     ..     */
  322. } OPCODE_;
  323.  
  324. typedef struct
  325. {
  326.     char
  327.         version[4];
  328.     INT32
  329.         offset[4];
  330. } BIN_HEADER_;                              /* see header structure at BOF */
  331.  
  332. typedef struct
  333. {
  334.     UNS16
  335.         size;
  336.     char
  337.         **element;                          /* used as (char *) by icmcomp */
  338. } LIST_;
  339.  
  340. typedef union
  341. {
  342.     char
  343.         *str;                               /* address of allocated string */
  344.     LIST_
  345.         list;                               /* list info of a list */
  346. } LS_UNION_;
  347.  
  348. typedef struct
  349. {
  350.     UNS16
  351.         count;                              /* allocation count */
  352.     LS_UNION_
  353.         ls;
  354. } INTER_;
  355.  
  356. typedef union
  357. {
  358.     INT16
  359.         intval;                             /* value of an int */
  360.     INTER_
  361.         *i;                                 /* intermediate alloc. structure */
  362. } VAR_UNION_;
  363.  
  364. typedef struct                              /* defined variable */
  365. {
  366.     E_TYPE_
  367.         type;                               /* maybe stringconst, int, list */
  368.     VAR_UNION_
  369.         vu;                                 /* value of the element */
  370. } VAR_;
  371.  
  372. #ifndef MSDOS
  373. struct _find_t                               /* abbreviated variant */
  374. {
  375.     char
  376.         name[_MAX_PATH];
  377.     unsigned
  378.         attrib;                             /* returned attribute */
  379. };
  380. #endif
  381.  
  382. typedef struct
  383. {
  384.     unsigned
  385.         attrib;                             /* requested attribute */
  386.     struct _find_t
  387.         find;                               /* _dos_find...()'s struct  */
  388. } ICMAKE_FIND_;
  389.  
  390.  
  391. BIN_HEADER_ *readheader (FILE *, unsigned);
  392.  
  393. extern ICMAKE_FIND_
  394.     ifs;                                    /* in: ./rss/findnext.c */
  395.  
  396. /*
  397.             replacement functions for non-dos systems
  398. */
  399.  
  400. #ifndef MSDOS
  401.  
  402. void        _makepath(char *, const char *, const char *,
  403.                       const char *, const char *);
  404. void        _splitpath(const char *, char *, char *, char *, char *);
  405. unsigned    _dos_findfirst(char *, unsigned, struct _find_t *);
  406. unsigned    _dos_findnext(struct _find_t *);
  407.  
  408. /*  ICCE getopt functions   */
  409. int         ic_getoptindex(void);
  410. int         ic_getopt(int *, char **);
  411. char        *ic_getoptval(int *, char **);
  412.  
  413. /*  and their mappings      */
  414. #define     getoptindex ic_getoptindex
  415. #define     getopt      ic_getopt
  416. #define     getoptval   ic_getoptval
  417.  
  418. int         _spawnlp(int, const char *, const char *, ...);           /* ok */
  419. int         _spawnvp(int, const char *, const char **);               /* ok */
  420. void        copyright(char *, char *, char *, int);                   /* ok */
  421. char        *program_name(char *);                                    /* ok */
  422. unsigned    redirect_start(unsigned, unsigned);                       /* ok */
  423. char        *_strlwr(char *);                                         /* ok */
  424.  
  425. #define     _heapmin()
  426.  
  427. char        *stresc(char *);                                           /* ok */
  428. int         chesc(char *, int *);                                      /* ok */
  429. char        *fgetz (char *, unsigned, FILE *);                         /* ok */
  430.  
  431. #endif  /*  MSDOS   */
  432.  
  433. char *change_ext (char *, char *);
  434. char *change_base (char *, char *);
  435. char *change_path (char *, char *);
  436. char *filefound();                          /* test attrib/pattern  */
  437. char *findfirst(char *, unsigned);          /* first entry matching pattern */
  438. char *findnext();                           /* remaining matching entries   */
  439. char *get_ext (char*);
  440. char *get_base (char*);
  441. char *get_path (char*);
  442. char *getstring (FILE *, INT32, UNS16);
  443. char *hexstring (UNS16, UNS16);
  444. char *xstrdup (char *);
  445. char *xstrcat (char *, char *);
  446.  
  447. void error (char *, ...);
  448. void spawn_err (char *);
  449.  
  450. void *xrealloc (void *, int);
  451.  
  452. int exists  (char *);
  453. int older   (char *, char *);
  454. int younger (char *, char *);
  455.  
  456. INT16 getint16 (FILE *);
  457.  
  458. OPCODE_ getopcode (FILE *);
  459.  
  460. UNS16 getvar (FILE *, BIN_HEADER_ *, VAR_ **);
  461.  
  462. VAR_ initvar (VAR_);
  463.